package com.itbaizhan.shopping_payment_service.util;

import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;

import java.util.HashMap;
import java.util.Map;

public class ZfbVerifierUtils {
    public static boolean isValid(Map<String, String[]> requestParameterMap, String alipayPublicKey) {
        /**
         * 1、获取支付宝post发送来的信息
         */
        Map<String, String> resultMap = new HashMap<String, String>();
        for (Object v : requestParameterMap.entrySet()) {
            Map.Entry<String, String[]> item = (Map.Entry<String, String[]>) v;
            resultMap.put(item.getKey(), item.getValue()[0]);
        }
        try {
            return AlipaySignature.rsaCheckV1(resultMap,
                            alipayPublicKey, "UTF-8", "RSA2");
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        return false;
    }
}
